import Base from '@/views/base'
import api from '../../api/article'
import { filterHTMLTag } from '../../utils/common'
export default class BLL extends Base { 
  async fetch (init = false) {
    const res = await api.GetArticle({
      PageIndex: this.vm.page.curIndex,
      PageSize: this.vm.page.count
    }, {load: false})
    if (res) {
      // console.log('res:', res)
      if (init) {
        this.vm.dataList = []
        this.vm.page.curIndex = 1
      }
      this.vm.loading = false
      this.vm.page.curIndex += 1
      res.Data.forEach(ele => {
        ele.content = filterHTMLTag(ele.content)
      })
      this.vm.dataList = this.vm.dataList.concat(res.Data)
      if (this.vm.dataList.length === res.Total) {
        this.vm.finished = true
      }
    } 
  }
  
  async refresh () {
    this.vm.dataList = []
    this.vm.page.curIndex = 1
    this.vm.loading = true
    this.vm.finished = false
    await this.fetch(true)
    this.vm.isLoading = false
  }

  async GetDetail (e) {
    const res = await api.GetArticleDetail({
      id: e
    })
    if (res) {
      // console.log('res:', res)
      this.vm.dataObj = res.Data
    }
  }
}